<!--  在Echarts.vue文件中 -->
<template>
  <div class="Echarts">
    <div id="main" style="width: 600px;height: 400px;"></div>
  </div>
</template>

<script>
export default {
  name: "Echarts",
  data() {
    return {
      option: {
        title: {
          text: "学生成绩统计图"
        },
        tooltip: {},
        legend: {
          data: ["分数"]
        },
        xAxis: {
          data: ["数学", "音乐", "计算机", "表演", "作曲", "作词"]
        },
        yAxis: {},
        series: [
          {
            name: "销量",
            type: "bar",
            data: [5, 20, 36, 10, 10, 20]
          }
        ]
      }
    };
  },
  methods: {
    myEcharts() {
      var myChart = this.$echarts.init(document.getElementById("main"));
      //配置图表
      var option = {
        title: {
          text: "学生成绩统计图"
        },
        tooltip: {},
        legend: {
          data: ["分数"]
        },
        xAxis: {
          data: ["数学", "音乐", "计算机", "表演", "作曲", "作词"]
        },
        yAxis: {},
        series: [
          {
            name: "销量",
            type: "bar",
            data: [5, 20, 36, 10, 10, 20]
          }
        ]
      };
      myChart.setOption(option);
    }
  },
  mounted() {
    // this.$axios.get().then{
    //     // this.myEcharts();
    // }

    this.option.series.data = [5, 10, 10, 10, 10, 10];

    console.log(this.option.series.data);
    var myChart = this.$echarts.init(document.getElementById("main"));

    myChart.setOption(this.option);
  }
};
</script>

<style></style>
